package com.h2.ref.server.user.pref;

import java.util.Map;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Application;
import javax.ws.rs.core.MediaType;

import org.springframework.context.annotation.Scope;

import com.sun.jersey.api.json.JSONWithPadding;

@Path("/user")
@Scope("singleton")
public class UserPreferenceServiceJson extends Application {

   private Map<String, String> _preferences;
   
   ////
   ////
   
   @GET
   @Produces(MediaType.APPLICATION_JSON)
   @Path("/preferences")
   public JSONWithPadding pereferencesJson() {
      return new JSONWithPadding(getPreferences());
   }
   
   @GET
   @Produces(MediaType.APPLICATION_JSON)
   @Path("/preference")
   public JSONWithPadding preferenceJson(
         @QueryParam("uid")
         String uid) {
      return new JSONWithPadding(
            (preference(uid) == null) ? "" : preference(uid));
   }
   
   public String preference(String uid) {
      return getPreferences().get(uid);
   }

   /**
    * @return the preferences
    */
   public Map<String, String> getPreferences() {
      return _preferences;
   }

   /**
    * @param preferences the preferences to set
    */
   public void setPreferences(Map<String, String> preferences) {
      _preferences = preferences;
   }
   
}
